import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Queue;

public class LeetCode641 {

    LinkedList<Integer> queue = new LinkedList<>();
    private int size;
    private int capacity;

    public LeetCode641(int capacity) {
        this.capacity = capacity;
    }

    //添加头
    public boolean insertFront(int value) {
        if (isFull()) {
            return false;
        }
        queue.offerFirst(value);
        size++;
        return true;
    }

    //添加尾
    public boolean insertLast(int value) {
        if (isFull()) {
            return false;
        }
        queue.offerLast(value);
        size++;
        return true;
    }

    //删除头
    public boolean deleteFront() {
        if (isEmpty()) {
            return false;
        }
        queue.pollFirst();
        size--;
        return true;
    }

    //删除尾
    public boolean deleteLast() {
        if (isEmpty()) {
            return false;
        }
        queue.pollLast();
        size--;
        return true;
    }

    //获取头
    public int getFront() {
        if (isEmpty()) {
            return -1;
        }
        return queue.peekFirst();
    }

    //获取尾
    public int getRear() {
        if (isEmpty()) {
            return -1;
        }
        Integer rear = queue.peekLast();
        if (rear != null) {
        return rear.intValue();
        }else{
            return -1;
        }
    }

    //判断是否为空
    public boolean isEmpty() {
        return size == 0;
    }

    //判断队列是否满了
    public boolean isFull() {
        return size == capacity;
    }
}
